page header

How To Work Database First

LLBLGen Pro v3 supports both Database First and Model First development. This article describes briefly which functionality of the designer is available to you when you want to work Database First as well as how the typical Database First work flow looks like.

Work flow of Database First

The schematic workflow of Database First development looks like the following:

Database First workflow

Schematic workflow of Database First

The flow of data is from the Database Schema Elements inside an RDBMS, e.g. SQL Server, to the Abstract Entity Model and Relational Model Data in a Relational Model Data storage inside LLBLGen Pro. The Database Schema Elements, e.g. a catalog with a schema and a set of tables, are edited by an external tool in the RDBMS. Two processes are used to retrieve the definitions of these Database Schema Elements: Add Relational data from a Database and Refresh Relational Data from a Database. Both result in Relational Model Data which is used as mapping targets for the elements in the Abstract Entity Model.

Let's break this down into smaller steps, from creating a project to creating a set of entities and refreshing the catalog.

  1. Create a project in the LLBLGen Pro designer and choose a target framework
  2. After you have examined and eventually adjusted the Project Settings and have clicked OK, Right-Click the node 'Relational Model Data' in the Project Explorer or Catalog Explorer and select Add Relational Model data from a Database from the context menu
  3. The Relational Model Data Retrieval Wizard is started. Complete the wizard's steps to obtain the relational model data from your database. Check at least 1 table with some fields.
  4. You now have a Relational Model Data storage with Relational Model Data in the project. Go to the Catalog Explorer and examine what's been retrieved by LLBLGen Pro
  5. In Catalog Explorer, Right-click the catalog node, or schema node and select Reverse Engineer Tables to Entity Definitions... from the context menu.
  6. The Reverse Engineering Element Editor is opened. Examine the names pre-generated and check all checkboxes in front of the elements in the grid. Then click the Add to Project button.
  7. The Project Explorer now shows one or more entity definitions. You now have reverse-engineered tables, their fields, primary key constraints and FK constraints to an Abstract Entity Model with entity definitions, fields, identifying field sets and relationships. Open one or more entities in their editor by right-clicking them in Project Explorer and select 'Edit...'
  8. Make a change to the database schema in your RDBMS, e.g. remove a field of a table which is mapped by an entity in your project.
  9. Right-click the Relational Model Data Storage node (right below the 'Relational Model Data' node) in Project Explorer or Catalog Explorer and select Refresh Relational Model Data from a Database from the context menu.
  10. Again, the Relational Model Data Retrieval Wizard is started. Complete the wizard's steps again to obtain the relational model data from your database.
  11. LLBLGen Pro will now migrate your Abstract Entity Model and will show the log of the actions performed afterwards. If you for example removed a field in the database, or renamed a field in the database, it will show you that it for example has left a field unmapped as there's  no target field found, or has mapped the entity field on a different field now (the renamed field).
  12. Validate the project and generate code by pressing F7 or by selecting Project -> Generate Source-code from the main menu.

Steps 8-12 are the typical work cycle from then on: you alter the database, refresh the catalog, check the changes made to the model, generate code again and you start again by altering the database....

Tools and functionality available to you for working Database First

The designer contains a lot of functionality, both visible and hidden beneath the surface, which help you work with an Abstract Entity Model using a Database First workflow. The following list of features are mainly used for and designed for working Database First.

Additionally, the rich editing system of the designer for the Abstract Entity Model elements is at your disposal.

Mixing Database First with Model First

It's ok to mix a Database First workflow with a Model First workflow: The LLBLGen Pro designer performs a validation of the project before the refresh process is started and if it detects changed Relational Model Data, you are required to export those changes first and apply them to your schema in your RDBMS. Refreshing the relational model data will then work with up-to-date schema data which matches the relational model data in the Relational Model Data storage in the project.


LLBLGen Pro Designer v3.5 documentation. ©2002-2012 Solutions Design